<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>上传健康登记信息</title>
    <link rel="stylesheet" href="/vendor/simple-line-icons/css/simple-line-icons.css">
    <link rel="stylesheet" href="/vendor/font-awesome/css/fontawesome-all.min.css">
    <link rel="stylesheet" href="/css/styles.css">
</head>
<body>
<div class="content">
    <div class="container-fluid">
        <div class="row">
            <div class="col-md-10">
                <div class="card">
                    <div class="card-header bg-light">
                        上传健康登记信息
                    </div>
                    <div class="card-body">
                        <div class="row mb-5">
                            <div class="col-md-4 mb-4">
                                <div class="text-muted small">健康登记信息<br/>(备注若没有则可不用填)</div>
                            </div>

                            <div class="col-md-8">
                                <div class="row">
                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="form-control-label">学号/工号</label>
                                            <input class="form-control" id="user_id" name="user_id">
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="form-control-label">学院</label>
                                            <input class="form-control" id="college" name="college">
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="form-control-label">姓名</label>
                                            <input class="form-control" id="name" name="name">
                                        </div>
                                    </div>

                                    <div class="col-md-3">
                                        <div class="toggle-switch" data-ts-color="primary">
                                            <label for="permission" class="ts-label">是否外出</label>
                                            <input id="permission" type="checkbox" hidden="hidden">
                                            <label for="permission" class="ts-helper"></label>
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="form-control-label">登记时间</label>
                                            <input class="form-control" id="regtime" name="regtime">
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="form-control-label">工作状态</label>
                                            <input class="form-control" id="work_situ" name="work_situ">
                                        </div>
                                    </div>

                                    <div class="col-md-6">
                                        <div class="form-group">
                                            <label class="form-control-label">备注</label>
                                            <input class="form-control" id="remark" name="remark">
                                        </div>
                                    </div>

                                </div>

                            </div>
                        </div>

                        <hr>

                    </div>

                    <div class="card-footer bg-light text-right">
                        <button id="save" class="btn btn-primary">添加</button>
                        <!--可能会出错-->
                        <a href="/user/reginfonow"><button type="submit" class="btn btn-outline-danger">取消</button></a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="/vendor/jquery/jquery.min.js"></script>
<script src="/vendor/popper.js/popper.min.js"></script>
<script src="/vendor/bootstrap/js/bootstrap.min.js"></script>
<script src="/vendor/chart.js/chart.min.js"></script>
<script>
    $("#save").click(function () {
        var user_id=$("#user_id").val();
        var college=$("#college").val();
        var name=$("#name").val();
        var heal_situ=$("#heal_situ").val();
        var regtime=$("#regtime").val();// --- 这个需要一个 timepicker
        var work_situ=$("#work_situ").val();
        var is_out;
        var permission = $('#permission:checked').val();
        var remark=$("#remark").val();

        if(permission=="on"){
            is_out=1;
        }else{
            is_out=0;
        }
        if(user_id==null||user_id==""){
            alert("学号/工号为空");
            return false;
        }else if(college==null||college==""){
            alert("学院为空");
            return false;
        }else if(name==null||name==""){
            alert("姓名为空");
            return false;
        }else if(heal_situ==null||heal_situ==""){
            alert("健康状况为空");
            return false;
        }else if(regtime==null||regtime==""){
            alert("登记时间为空");
            return false;
        }else if(work_situ==null||work_situ==""){
            alert("工作状态为空");
            return false;
        }

        var data = {
            "user_id":user_id,
            "college":college,
            "name":name,
            "heal_situ":heal_situ,
            "is_out":is_out,
            "regtime":regtime,
            "work_situ":work_situ,
            "remark":remark
        };
        $.ajax({
            url : "/user/insertHealth",     //后台请求的数据
            data:data,
            type : "post",                   //请求方式
            async : true,                   //是否异步请求
            success : function(data) {      //如果请求成功，返回数据。
                if(data=="true"){
                    alert("上传成功！");
                    window.location.href='/user/reginfonow';
                }else{
                    alert("上传失败");
                }
            },
        });
    });


</script>

</body>
</html>